#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef unsigned long long ull;
typedef pair<i64, i64> PII;
typedef unordered_map<string, int> USI;
typedef queue<string> QS;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define lowbit(x) (x & -x)
#define _for(i, a, b) for (int i = a, I_MAX = b; i <= I_MAX; i++)
#define _rep(i, a, b) for (int i = a, I_MIN = b; i >= I_MIN; i--)
#define KS                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int rx[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ry[8] = {1, 2, 2, 1, -1, -2, -2, -1};
const int MOD = 998244353;
const int INF = 0x3f3f3;
const int N = 2e6 + 10;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445;

void print(__int128 x)
{
    if (!x)
        return;
    if (x < 0)
        putchar('-'), x = -x;
    print(x / 10);
    putchar(x % 10 + '0');
}

i64 gcd(i64 a, i64 b)
{
    return b ? gcd(b, a % b) : a;
}

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    return x * f;
}

i64 inv(i64 a, i64 b)
{
    i64 res = 1;
    while (b > 0)
    {
        if (b % 2 == 1)
        {
            res = (res * a);
        }
        a = (a * a);
        b >>= 1;
    }
    return res;
}

int n, m, q;

void solve()
{
    cin >> n >> m;
    q = n * m;
    vector<string> a(n + 1);
    vector<vector<int>> d(q + 10, vector<int>(q + 10, 1e9));
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] = " " + a[i];
    }

    // for (int i = 1; i <= n; i++)
    //     cout << a[i] << endl;

    for (int i = 1; i <= q; i++)
        d[i][i] = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            int u = (i - 1) * m + j;
            for (int k = 0; k < 4; k++)
            {
                int x = i + dx[k], y = j + dy[k];
                if (x <= 0 || x > n || y <= 0 || y > m || a[x][y] == '#')
                    continue;
                int v = (x - 1) * m + y;
                d[u][v] = 1;
            }
        }
    }

    for (int k = 1; k <= q; k++)
    {
        for (int i = 1; i <= q; i++)
        {
            for (int j = 1; j <= q; j++)
            {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    // for(int i = 1;i <= q;i++)
    // {
    //     for(int j = 1;j <= q;j++)
    //     {
    //         cout << d[i][j];
    //     }
    //     cout << endl;
    // }

    int ans = 0;
    for (int i = 1; i <= q; i++)
    {
        for (int j = 1; j <= q; j++)
        {
            if (d[i][j] > 1e6)
                continue;
            ans = max(ans, d[i][j]);
        }
    }

    cout << ans << endl;
}

int main()
{
    int t = 1;
    // cin>>t;
    mt19937 Rnd(time(0));
    while (t--)
    {
        solve();
    }
    return 0;
}